import imagecache
import image
from pygame import Surface

class Building:
    def __init__(self, width, height):
        self.width = width
        self.height = height
        self.door_coordinates = None
        self.image = None
        
    def walkable(self):
        return False
    
    def set_door(self, (x, y)):
        self.door_coordinates = (x, y)
    
    def get_image(self):
        if not self.image:
            #make left side
            ret = Surface((self.width, self.height))
            
            left_image = imagecache.get_image('house-left')
            ret.blit(image.tile_image(left_image, left_image.get_width(), self.height), (0,0))
            
            right_image = imagecache.get_image('house-right')
            ret.blit(image.tile_image(right_image, right_image.get_width(), self.height), (self.width - right_image.get_width(),0))
            
            centre_image = imagecache.get_image('house-centre')
            centre_width = self.width - left_image.get_width() - right_image.get_width()
                
            ret.blit(image.tile_image(centre_image, centre_width, self.height), (left_image.get_width(), 0))
            
            if self.door_coordinates:
                ret.blit(imagecache.get_image('door'), self.door_coordinates)
                
            self.image = ret
        return self.image
        